package Day2025_03_19;

public class LeetCode5 {
    public String longestPalindrome(String s) {
        char[] ss= s.toCharArray();
        int n = ss.length;
        boolean[][] dp = new boolean[n][n];
        int begin = 0, len = 0;
        for (int i = n - 1; i >= 0; i--) {
            for (int j = i; j < n; j++) {
                if (ss[i] == ss[j]) dp[i][j] = i + 1 < j ? dp[i + 1][j - 1] : true;
                if (dp[i][j] && len < j - i + 1) {
                    begin = i;
                    len = j - i + 1;
                }
            }
        }
        return s.substring(begin, len + begin);
    }
}
